#ifndef SERVER_H_
#define SERVER_H_

//boost header files
#include <boost/asio.hpp>
#include <boost/noncopyable.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/optional.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/signal.hpp>
#include <boost/signals.hpp>
#include <boost/signals/connection.hpp>

//std header files
#include <string>
#include <queue>

//project header files
#include "SRVConnection.h"
#include "../Validator/Scheme.h"
#include "DataContainer.h"


/*! 
* Server trieda
* 
* Trieda predstavuje implementaciu serveru ktory prijima spojenia na 
* danom porte a spracuvava prijate data
*/
class Server : public boost::noncopyable
{
	public:
		//! Konstruktor
		/*!
				\param port cislo portu na ktorom bude server prijimat spojenia
				\param thread_pool_size pocet spojeny ktore naraz vie obsluzit
		*/
		explicit Server(const std::string &port,std::size_t thread_pool_size);


		//! Funkcia Run
		/*!
			Sluzi na spustenie servera.
		*/
		void Run();
		

		//! Funkcia Stop
		/*!
			Sluzi na zastavenie servera.
		*/
		void Stop();
		
		
		typedef boost::optional<boost::shared_ptr<ConnectionContainer> > ReceivedContainer;

		ReceivedContainer GetReceived();

	private:
		//////////////////////////////////////////////////////////////////////////
		//							MEMBER FUNCTIONS	
		//////////////////////////////////////////////////////////////////////////
		void handle_accept(const boost::system::error_code &er);

		//void handle_received(DataContainer receivedContainer);
		//////////////////////////////////////////////////////////////////////////
		//							MEMBER VARIABLES
		//////////////////////////////////////////////////////////////////////////
		boost::asio::io_service myIO_service;
		boost::asio::ip::tcp::acceptor myAcceptor;
		boost::mutex myMutex;
		std::size_t myThreadPoolSize;
		connection_ptr myNewConnection;
		std::queue<boost::shared_ptr<ConnectionContainer> > myReceived;
		
};

#endif